package com.itwn.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itwn.entity.Cinema;
import com.itwn.entity.Hall;
import com.itwn.entity.HallType;
import com.itwn.mapper.HallMapper;
import com.itwn.vo.HallTypeVo;
import com.itwn.vo.HallVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HallService {
    private HallMapper hallMapper;

    @Autowired
    public HallService(HallMapper hallMapper) {
        this.hallMapper = hallMapper;
    }

    public PageInfo<HallVo> findByCon(Integer pageNum,Integer pageSize,String hallName, String cinemaName, Integer hallTypeId){
        PageHelper.startPage(pageNum,pageSize);
        List<HallVo> hallVos = hallMapper.selectByCon(hallName, cinemaName, hallTypeId);
        PageInfo<HallVo> pageInfo = new PageInfo<>(hallVos);
        return pageInfo;
    }

    public List<HallType> findAllType() {
        List<HallType> hallTypeList = hallMapper.selectAllType();
        return hallTypeList;
    }

    public int addHall(Hall hall) {
        int i = hallMapper.insert(hall);
        return i;
    }

    public int updateHall(Hall hall) {
        int i = hallMapper.updateByPrimaryKey(hall);
        return i;
    }

    public int removeHall(Integer hallId) {
        int i = hallMapper.updateHallState(hallId);
        return i;
    }

    public List<HallTypeVo> findAllHallTypes(){
        return hallMapper.selectAllHallType();
    }
}
